﻿using Module.Common.Common;
using Module.Common.PubEvent;
using Module.Common.Views;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;

namespace Module.Common.ViewModels
{
    public class BestMovesViewModel : BindableBase
    {
        private readonly IEventAggregator Ea;
        private DataTable _bestMoveDataTable;
        public DataTable BestMoveDataTable { get { return _bestMoveDataTable; } set { SetProperty(ref _bestMoveDataTable, value); } }
        private string _bestMove; // 最佳着法提示信息
        public string BestMove { get { return _bestMove; } set { SetProperty(ref _bestMove, value); } }


        public BestMovesViewModel(IEventAggregator ea)
        {
            Ea = ea;
            BestMoveDataTable = new();
            Ea.GetEvent<ServiceMessageEvent>().Subscribe(ServiceMessageProcess);
            Ea.GetEvent<SystemMessageEvent>().Subscribe(SystemMessageProcess);
            BestMoveDataTable = new DataTable();
            BestMoveDataTable.Columns.Add("id");
            BestMoveDataTable.Columns.Add("score");
            BestMoveDataTable.Columns.Add("movestr");

        }

        private void ServiceMessageProcess(ServiceMessage obj)
        {
            switch (obj.MessageName)
            {
                case "BestMoveOk":
                    BestMove = obj.Content;
                    BestMoveDataTable = obj.BestMoveData;
                    break;
                default:
                    break;
            }
        }
        private void SystemMessageProcess(SystemMessage obj)
        {
            switch (obj.MessageName)
            {
                case "reStart": // 重新开局
                    BestMoveDataTable.Clear();
                    break;
                default:
                    break;
            }
        }
    }
}
